import { Component, OnInit } from '@angular/core';
import { getHoverContext } from '../../service/utils/hoverContext.js';

@Component({
    selector: 'app-hover-modal',
    templateUrl: './hover-modal.component.html',
    styleUrls: ['./hover-modal.component.scss'],
})
export class HoverModalComponent implements OnInit {
    position = [-100, -100];
    data = undefined;
    setPosition(position) {
      this.position = position
      console.log("position",position)
      var hover = document.getElementById('hover')
      hover.style.top = position[1]-50+'px'
      hover.style.left = position[0]+'px'
    }
    setData(data) {
      this.data = data
      console.log("data",data)
    }
    transStatus(data) {
        if (data.status === 1001) {
            return '正常运行';
        } else if (data.status === 1002) {
            return '尚未安装';
        } else if (data.status === 1003) {
            return '已经停用';
        } else if (data.status === 4444) {
            return '正在报警';
        } else {
            return '未知';
        }
    }
    constructor() {}

    ngOnInit(): void {
      getHoverContext().setPositionFunc(this.setPosition)
      getHoverContext().setDataFunc(this.setData)
      var hover = document.getElementById('hover')
      hover.style.top = this.position[1]-100+'px'
      hover.style.left = this.position[0]+'px'
    }
}
